
   <script>
   //nếu hàm $("#mga_pt_slsp").ready bên function.js chạy không được thì sài hàm này de nguyên ở đây
   // bỏ cái thư viện  src="//code.jquery.com/jquery-1.11.0.min.js" vào thẻ head 
	$(window).load(function() {		
    		var kq;
            if(mga_checkCookie("c_mga_sp_in_page")==true)
			{
				kq=mga_getCookie("c_mga_sp_in_page");
			}else
			{
				mga_setCookie("c_mga_sp_in_page",20,1);
				kq=20;
			}
			$("#mga_pt_slsp").val(kq);
	});  
   </script>
   
    <div id="mga_div_edt_admin_product" class="mga_div_edt_admin_product" hidden>
    	<span id="mga_spn_name_edt_admin_product"></span>      
    		<textarea name="mga_ttr_edt_admin_product" id="mga_ttr_edt_admin_product" rows="10" cols="80">
                
            </textarea>
            <script>
				//call ckeditor          
                CKEDITOR.replace( 'mga_ttr_edt_admin_product' );
            </script>
         <button id="mga_btn_ok_edt_admin_product" value="">Ok</button>
         <button id="mga_btn_huy_edt_admin_product">Hủy</button>
    </div> 
     
     <div class="page-content-admin col-xs-10 mga_content_product_admin">
        <div class="header-content">
            <i class="fa fa-gift"></i>Sản Phẩm
            <div class="divider"></div>
            <div class="col-xs-3">
                <div class="form-group">
                    <label class="lbl-view" for="exampleInputPassword2">Xem</label>
                    <input type="text" class="form-control input-radius-0 input-sm input-view" id="mga_pt_slsp" maxlength="3"  onkeypress='mga_onkey_number()'>
                    <button type="button" class="btn btn-success btn-sm">Xem</button>
                    <label class="lbl-view" for="exampleInputPassword2">sản phẩm</label>
                </div>
            </div>
        </div>
        
            <table class="table  table-bordered">
                <thead>
                    <tr>
                        <th style="width: 1%;"><input title="Check all" type="checkbox" name="check-all"  onclick="CheckAll(this)" /></th>
                        <th style="width: 7%;">IMG</th>
                        <th style="width: 21%;">Tên Sản Phẩm</th>
                        <th style="width: 15%;">Phân loại</th>
                        <th style="width: 10%;">Đơn vị</th>
                        <th style="width: 10%;">Giá</th>
                        <th style="width: 7%;">Mô tả</th>
                        <th style="width: 10%;">Kích thước</th>
                        <th style="width: 10%;">Hướng dẩn</th>
                        <th style="width: 10%;">Tác vụ</th>
                    </tr>
               
                    <tr class="mga_tr_d">
                    <form>
                        <td></td>
                        <td></td>
                        <td>
                        <input type="text" id="txt_int_name_product" name="txt-name-product" placeholder="Tên sản phẩm" size="35"/>
                        </td>
                        <td>
                            <select id="slc_int_menu_product" name="sle-cats" class="">
                            <?php												
								foreach($data_menu_product as $rows)
											{
												$name=$rows['name'];
												$id=$rows['id'];
												$parent=$rows['parent'];
												$ss=0;// set id parent rowed
												if($parent==0)
												{
													echo'<option value="'.$id.'_k'.'" class="mga_er" disabled>'.$name.'</option>';
													$ss=$id; // get id parent rowed													
													
														foreach($data_menu_product as $rows)
														{
														$name=$rows['name'];
														$id=$rows['id'];
														$parent=$rows['parent'];
															if($parent==$ss)
															{
																//value="'.$id.'_c'.'" >'.$name.''
															echo'<optgroup label="'.$name.'">';
															$ss1=$id;
															
																foreach($data_menu_product as $rows)
																{
																	$name=$rows['name'];
																	$id=$rows['id'];
																	$parent=$rows['parent'];
																	if($parent==$ss1)
																		{
															echo'<option value="'.$id.'_c'.'" >'.$name.'</option>';
																		}
																}
															echo '</optgroup>';
															}
														}
													
													
												}							
											}
								?>             
                            </select>
                        </td>
                        <td>
                         <select id="slc_int_unit_product" name="sle-quanlity" class="">
                                <?php
								foreach($data_unit as $rows)
                                {
									$name=$rows['name'];
									$id=$rows['id'];
									echo'<option value="'.$id.'">'.$name.'</option>';
								}
								?>
                            </select>
                        </td>
                        <td>
    					<input id="mga_ipt_ist_gia_admin_product" class="" value="" onkeypress='mga_onkey_number()' size="12" name="txt-price" maxlength="11" placeholder="giá sản phẩm"/>
                        </td>
                        <td id="mga_td_show_edt_admin_product_mt_new" >
                        	<textarea id="mga_ttr_admin_product_mt_new" hidden></textarea>
                        	<img src="../public/images/admin/t.png" width="20" height="20" title="20 ký tự đầu">
                        </td>
                        <td id="mga_td_show_edt_admin_product_kt_new" >
                        <textarea id="mga_ttr_admin_product_kt_new" hidden></textarea>
                       		<img src="../public/images/admin/t.png" width="20" height="20" title="20 ký tự đầu">
                        </td>
                        <td id="mga_td_show_edt_admin_product_hd_new">
                        <textarea id="mga_ttr_admin_product_hd_new" hidden></textarea>
                        	<img src="../public/images/admin/t.png" width="20" height="20" title="20 ký tự đầu">
                        </td>
                        <td>
                        <button id="mga_btn_int_prd_admin" title="Thêm mới" type="button">
                        	<img src="../public/images/admin/+.png" width="20" height="20" >
                        </button>
                        </td>
                    </form>
                   
                    </tr>
                </thead>
                <tbody id="mga_ct_ud_admin_product">                    
                   
                     <?php
					 //lay so trang dang 
					 if(isset($_GET['t'])==NULL||isset($_GET['t'])=="")
					 {
					 	 $t=1;
					 }
					 else
					 {
						$t=$_GET['t'];
					 }
					
					 //phan trang
					 $t_sp=0;//tong sản phẩm
					 foreach($data_product as $rows)
					 {$t_sp++;}
					 
					 //dang lam
					 if($_COOKIE['c_mga_sp_in_page']==NULL)
					 {
						 $_COOKIE['c_mga_sp_in_page']=20;
					 }
					 //end dang lam
					 
					 if($t_sp%$_COOKIE['c_mga_sp_in_page']!=0)
					 {
						 $s_t=(int)($t_sp/$_COOKIE['c_mga_sp_in_page'])+1;
					 }else
					 {
						 $s_t=$t_sp/$_COOKIE['c_mga_sp_in_page'];//so trang
					 }
					 
					 					
					 $i=0;//dem san pham
                     foreach($data_product as $rows)
					 {	 
					 	$i++;
						 $id_pr=$rows['id_product'];						
						 $ten=$rows['name'];
						 $gia=number_format($rows['price']);
						 $mt=$rows['text'];						 
						 $dv=$rows['units'];
						 $loai=$rows['id_menu'];
						 $kt=$rows['text_1'];
						 $hd=$rows['text_2'];
						 //get name_dv
						 foreach($data_unit as $rows)
                                {
									$name=$rows['name'];
									$id=$rows['id'];
									if($id==$dv)//$id_t
									{
										$name_dv=$name;
									}									
								}
						//get name_loai
						foreach($data_menu_product as $rows)
                                {
									$name=$rows['name'];
									$id=$rows['id'];
									if($id==$loai)//$id_t
									{
										$name_loai=$name;
									}									
								}
						//cl
						$cl="";
						if($i%2==0)
						{$cl="mga_tr_d";}
						//phan trang theo i i= dien bat dau <= diem ket thuc
						if($i>=$t*$_COOKIE['c_mga_sp_in_page']-$_COOKIE['c_mga_sp_in_page']+1 
							and $i<=$t*$_COOKIE['c_mga_sp_in_page']) 							
							{
									 echo'
						<tr class="mga_hover_tr_admin_product '.$cl.'" id="mga_hover_tr_ad_prt_'.$id_pr.'">
                        <td><input type="checkbox" name="check-product" id="#id-product"/></td>
                        <td id="td_img_admin_product_2">						
                        <img id="mga_change_img_hover_admin_product_'.$id_pr.'" class="mga_show_img_admin_product" src="" height="200" hidden>       
						    
						<div class="mga_div_ct_upimg">                            	
                        <img id="mga_img_hover_admin_product_1_'.$id_pr.'" width="10" height="10" src="../public/images/product/mga_prt/min_1_'.$id_pr.'.jpg" >
						<input id="mga_ipt_up_img_1_'.$id_pr.'" name="" type="file" class="mga_ipt_fle" >
						</div>
						<div class="mga_div_ct_upimg"> 
                        <img id="mga_img_hover_admin_product_2_'.$id_pr.'" width="10" height="10" src="../public/images/product/mga_prt/min_2_'.$id_pr.'.jpg">
						<input id="mga_ipt_up_img_2_'.$id_pr.'" name="" type="file" class="mga_ipt_fle" >					
						</div>
						<div class="mga_div_ct_upimg"> 
                        <img id="mga_img_hover_admin_product_3_'.$id_pr.'" width="10" height="10" src="../public/images/product/mga_prt/min_3_'.$id_pr.'.jpg">
						<input id="mga_ipt_up_img_3_'.$id_pr.'" name="" type="file" class="mga_ipt_fle" >				
						</div>
						<div class="mga_div_ct_upimg">
                        <img id="mga_img_hover_admin_product_4_'.$id_pr.'" width="10" height="10" src="../public/images/product/mga_prt/min_4_'.$id_pr.'.jpg">
						<input id="mga_ipt_up_img_4_'.$id_pr.'" name="" type="file" class="mga_ipt_fle" >				
						</div>
                        </td>
                        <td>
							<span id="mga_spn_ad_prt_'.$id_pr.'_ten">'.$ten.'</span>
							<input id="mga_ad_prt_ud_'.$id_pr.'_ten"  value="'.$ten.'" size="35" hidden>							
						</td>
                        <td>
							<span id="mga_spn_ad_prt_'.$id_pr.'_loai" >'.$name_loai.'</span>
							<select id="mga_ad_prt_ud_'.$id_pr.'_loai"  hidden>
								';
						foreach($data_menu_product as $rows)
											{
												$name=$rows['name'];
												$id=$rows['id'];
												$parent=$rows['parent'];
												$ss=0;// set id parent rowed
												if($parent==0)
												{
													echo'<option value="'.$id.'_k'.'" class="mga_er" disabled>'.$name.'</option>';
													$ss=$id; // get id parent rowed													
													
														foreach($data_menu_product as $rows)
														{
														$name=$rows['name'];
														$id=$rows['id'];
														$parent=$rows['parent'];
															if($parent==$ss)
															{
																//value="'.$id.'_c'.'" >'.$name.''
															echo'<optgroup label="'.$name.'">';
															$ss1=$id;
															
																foreach($data_menu_product as $rows)
																{
																	$name=$rows['name'];
																	$id=$rows['id'];
																	$parent=$rows['parent'];
																	if($parent==$ss1)
																		{
																		$sld="";
																		if($loai==$id)
																		{$sld='selected';}
															echo'<option value="'.$id.'_c'.'" '.$sld.'>'.$name.'</option>';
																		}
																}
															echo '</optgroup>';
															}
														}
												}							
											}
								echo'
							</<select>
						</td>
                        <td>
							<span id="mga_spn_ad_prt_'.$id_pr.'_dv">'.$name_dv.'</span>
							<select id="mga_ad_prt_ud_'.$id_pr.'_dv" hidden>
								';
								foreach($data_unit as $rows)
                                {
									$name=$rows['name'];
									$id=$rows['id'];
									$sld="";
									if($dv==$id){$sld="selected";}									
									echo'<option value="'.$id.'" '.$sld.'>'.$name.'</option>';
								}
								echo'
							</select>
						</td>
                        <td>
							<span id="mga_spn_ad_prt_'.$id_pr.'_gia">'.$gia.'</span>							
							<input id="mga_ad_prt_ud_'.$id_pr.'_gia" class="mga_ud_format_num" value="'.$gia.'" onkeypress="mga_onkey_number()"  size="12" maxlength="11" hidden/>	
						</td>
                        <td id="mga_td_show_edt_admin_product_mt_'.$id_pr.'" n_pro="'.$ten.'">
							<textarea id="mga_spn_ad_prt_'.$id_pr.'_mt" hidden>'.$mt.'</textarea>
							<textarea id="mga_ttr_admin_product_mt_'.$id_pr.'" hidden>'.$mt.'</textarea>
               				<img src="../public/images/admin/t.png" width="20" height="20" title="'.substr($mt,0,40).'" > 
                        </td>
                        <td id="mga_td_show_edt_admin_product_kt_'.$id_pr.'" n_pro="'.$ten.'">
							<textarea id="mga_spn_ad_prt_'.$id_pr.'_kt" hidden>'.$kt.'</textarea>
							<textarea id="mga_ttr_admin_product_kt_'.$id_pr.'" hidden>'.$kt.'</textarea>
                        	<img src="../public/images/admin/t.png" width="20" height="20" title="'.substr($kt,0,40).'" >
                        </td>
                        <td id="mga_td_show_edt_admin_product_hd_'.$id_pr.'" n_pro="'.$ten.'">
							<textarea id="mga_spn_ad_prt_'.$id_pr.'_hd" hidden>'.$hd.'</textarea>
							<textarea id="mga_ttr_admin_product_hd_'.$id_pr.'" hidden>'.$hd.'</textarea>
                        	<img src="../public/images/admin/t.png" width="20" height="20" title="'.substr($hd,0,40).'" >
                        </td>
                        <td>
							<button type="button" id="mga_delete_'.$id_pr.'" value="'.$id_pr.'">
							<img src="../public/images/admin/-.png" width="20" height="20" title="xóa">
							</button>
						</td>
                    </tr>                    
						 ';
							}
						}
					 ?>
                </tbody>
            </table>
            <div align="center">
            <?php 
			//so trang
			for($k=1;$k<=$s_t;$k++)
				{if($s_t!=1)
				{
					echo'
						<a href="http://localhost/decorvn/admin/product?t='.$k.'">'.$k.'</a>
					';		
				}					
			}			
					echo'
					<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$t.'/'.$s_t.'</span>
					';	
			?>
            </div>
        </div>
    </div>
    
</div>


